'\" te
.\" Copyright 1989 AT&T
.\" Copyright (C) 2002, Sun Microsystems, Inc. All Rights Reserved
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH SOCKETPAIR 3SOCKET "Jan 10, 2001"
.SH NAME
socketpair \- create a pair of connected sockets
.SH SYNOPSIS
.LP
.nf
\fBcc\fR [ \fIflag\fR ... ] \fIfile\fR ... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR ... ]
#include <sys/types.h>
#include <sys/socket.h>

\fBint\fR \fBsocketpair\fR(\fBint\fR \fIdomain\fR, \fBint\fR \fItype\fR, \fBint\fR \fIprotocol\fR, \fBint\fR \fIsv\fR[2]);
.fi

.SH DESCRIPTION
.sp
.LP
The \fBsocketpair()\fR library call creates an unnamed pair of connected
sockets in the specified address family \fIdomain\fR, of the specified
\fItype\fR, that uses the optionally specified \fIprotocol\fR. The descriptors
that are used in referencing the new sockets are returned in \fIsv\fR[0] and
\fIsv\fR[1]. The two sockets are indistinguishable.
.SH RETURN VALUES
.sp
.LP
\fBsocketpair()\fR returns \fB\(mi1\fR on failure and \fB0\fR on success.
.SH ERRORS
.sp
.LP
The call succeeds unless:
.sp
.ne 2
.na
\fB\fBEAFNOSUPPORT\fR\fR
.ad
.RS 19n
The specified address family is not supported on this machine.
.RE

.sp
.ne 2
.na
\fB\fBEMFILE\fR\fR
.ad
.RS 19n
Too many descriptors are in use by this process.
.RE

.sp
.ne 2
.na
\fB\fBENOMEM\fR\fR
.ad
.RS 19n
There was insufficient user memory for the operation to complete.
.RE

.sp
.ne 2
.na
\fB\fBENOSR\fR\fR
.ad
.RS 19n
There were insufficient \fBSTREAMS\fR resources for the operation to complete.
.RE

.sp
.ne 2
.na
\fB\fBEOPNOTSUPP\fR\fR
.ad
.RS 19n
The specified protocol does not support creation of socket pairs.
.RE

.sp
.ne 2
.na
\fB\fBEPROTONOSUPPORT\fR\fR
.ad
.RS 19n
The specified protocol is not supported on this machine.
.RE

.sp
.ne 2
.na
\fB\fBEACCES\fR\fR
.ad
.RS 19n
The process does not have appropriate privileges.
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
MT-Level	Safe
.TE

.SH SEE ALSO
.sp
.LP
.BR pipe (2),
.BR read (2),
.BR write (2),
.BR socket.h (3HEAD),
.BR attributes (7)
.SH NOTES
.sp
.LP
This call is currently implemented only for the \fBAF_UNIX\fR address family.
